//
//  DriverViewController.swift
//  testRxSwift
//
//  Created by 火星人 on 2017/7/26.
//  Copyright © 2017年 火星人. All rights reserved.
//

import UIKit
import RxCocoa
import RxSwift

class DriverViewController: BaseViewController {
    
    var textField: UITextField!
    
    var disposed = DisposeBag()

    override func viewDidLoad() {
        super.viewDidLoad()

        textField = UITextField(frame: CGRect(x: 0, y: 80, width: self.view.width, height: 33))
        textField.backgroundColor = UIColor.lightGray.withAlphaComponent(0.2)
        self.view.addSubview(textField)
        
        let label = UILabel(frame: CGRect(x: 0, y: 130, width: self.view.width, height: 33))
        self.view.addSubview(label)
        
        let label1 = UILabel(frame: CGRect(x: 0, y: 170, width: self.view.width, height: 33))
        self.view.addSubview(label1)
        
        
        
        let obs = textField.rx.text.orEmpty
            .asDriver(onErrorJustReturn: "error")
            .filter({
                return $0.length > 0
            })
            .map({ (str) -> String in
                print("map")
                return str
            })
        
        obs.drive(label.rx.text)
            .disposed(by: disposed)
        
        obs.drive(label1.rx.text)
            .disposed(by: disposed)
        
        

    }
}
